<template>
	<div>
		<el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
			<h3 class="title">系统登录</h3>
			<el-form-item prop="name">
				<el-input type="text" v-model="ruleForm2.name" auto-complete="off" placeholder="账号"></el-input>
			</el-form-item>
			<el-form-item prop="password">
				<el-input type="password" v-model="ruleForm2.pword" auto-complete="off" placeholder="密码"></el-input>
			</el-form-item>
			<el-checkbox checked class="remember">记住密码</el-checkbox>
			<el-form-item style="width:100%;">
				<el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
				<!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		name: 'login',
		data() {
			return {
				logining: false, //加载
				checked: true, //记住密码
				ruleForm2: {
					name: '',
					pword: ''
				},
				rules2: {
					name: [{
							required: true,
							message: '请输入账号',
							trigger: 'blur'
						},
						//{ validator: validaePass }
					],
					pword: [{
							required: true,
							message: '请输入密码',
							trigger: 'blur'
						},
						//{ validator: validaePass2 }
					]
				},
			}
		},
		methods: {
			handleReset2() {
				this.$refs.ruleForm2.resetFields();
			},
			openHint(msg, type) {
				this.$message({
					message: msg,
					type: type
				});
			},
			handleSubmit2(ev) {
				var that = this;
				this.$refs.ruleForm2.validate((valid) => {
					if(valid) {
						//_this.$router.replace('/table');
						this.logining = true;
						var loginMess = {
							name: this.ruleForm2.name,
							password: this.ruleForm2.pword
						};
						this.$axios.post('https://mini.dem99.com/admin/login/login', loginMess)
							.then(function(res) {
								console.log(res);
								if(res.data.code == 0) {
									that.openHint("登录成功", "success");
									that.logining = false;
								} else if(res.data.code == 2) {
									that.openHint(res.data.msg, "error");
									setTimeout(function(){
										that.logining = false;
									},2000)									
								}
							})
							.catch(function(error) {
								console.log(error);
							});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}
		},

		created() {
			//			this.$axios.post('http://www.wwtliu.com/sxtstu/blueberrypai/getIndexBanner.php')
			//				.then(function(response) {
			//					console.log(response);
			//				})
			//				.catch(function(error) {
			//					console.log(error);
			//				});
		},
	}
</script>

<style scoped>
	.title {
		text-align: center;
	}
	
	.remember {
		margin: 20px 0;
	}
	
	.login-container {
		-webkit-border-radius: 5px;
		border-radius: 5px;
		-moz-border-radius: 5px;
		background-clip: padding-box;
		margin: 180px auto;
		width: 350px;
		padding: 35px 35px 15px 35px;
		background: #fff;
		border: 1px solid #eaeaea;
		box-shadow: 0 0 25px #cac6c6;
		.title {
			margin: 0px auto 40px auto;
			text-align: center;
			color: #505458;
		}
		.remember {
			margin: 0px 0px 35px 0px;
		}
	}
</style>